<?php


namespace App\Http\Controllers\Api;


use App\Services\UserService;
use Illuminate\Http\Request;

class UserController extends BaseController
{

    /**
     * @api {post} api/user/store 创建用户
     *
     * @param Request $request
     * @param UserService $service
     * @return mixed
     * @throws \Throwable
     */
    public function store(Request $request, UserService $service) {
        return $service->store($request->input(), true);
    }

    /**
     * @api {delete} api/user/destroy/{id} 删除用户
     *
     * @param UserService $service
     * @param $id
     * @return bool|mixed|null
     * @throws \Exception
     */
    public function destroy(UserService $service, $id){
        return $service->destroy($id);
    }

    /**
     * @api {post} api/user/update/{id} 更新用户
     *
     * @param Request $request
     * @param UserService $service
     * @param null $id
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|\Tymon\JWTAuth\Contracts\JWTSubject|null
     * @throws \Exception
     */
    public function update(Request $request, UserService $service, $id = null) {
        return $service->update($request->input(), $this->manager ? $id : \Auth::id());
    }

    /**
     * @api {get} api/user/info/{id} 用户信息
     *
     * @param Request $request
     * @param UserService $service
     * @param null $id
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|\Tymon\JWTAuth\Contracts\JWTSubject|null
     * @throws \Exception
     */
    public function show(Request $request, UserService $service, $id = null) {
        return $service->show($id, false, $abnormal = true, $isToken = false, $mode = 'account', $session = '', $request
            ->input('check', null), $request->input('mark', null));
    }

    /**
     * @api {get} api/user/paginate 用户分页
     *
     * @param Request $request
     * @param UserService $service
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function index(Request $request, UserService $service) {
        return $service->index($request->query());
    }

    /**
     * @api {get} api/user/menus 用户菜单
     *
     * @param Request $request
     * @param UserService $service
     * @return array
     * @throws \Exception
     */
    public function menus(Request $request, UserService $service) {
        return $service->menus($request->query());
    }

    /**
     * @api {get} api/user/print 打印用户
     *
     * @param Request $request
     * @param UserService $service
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function print(Request $request, UserService $service) {
        return $service->index($request->query());
    }

    /**
     * @api {get} api/user/export 导出用户分页
     *
     * @param Request $request
     * @param UserService $service
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
    public function export(Request $request, UserService $service) {
        return $service->index($request->query());
    }

    /**
     * @api {post} api/user/update/all 批量更新用户
     *
     * @param Request $request
     * @param UserService $service
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|\Tymon\JWTAuth\Contracts\JWTSubject|null
     * @throws \Exception
     */
    public function updateAll(Request $request, UserService $service) {
        return $service->updateAll($request->input());
    }
}
